<?php

namespace app\admin\model;

use think\Model;


class Reserve extends Model
{


    // 表名
    protected $name = 'reserve';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'pay_way_text'
    ];
    

    
    public function getPayWayList()
    {
        return ['1' => __('Pay_way 1'), '2' => __('Pay_way 2'), '3' => __('Pay_way 3'), '4' => __('Pay_way 4')];
    }


    public function getPayWayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_way']) ? $data['pay_way'] : '');
        $list = $this->getPayWayList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function store()
    {
        return $this->belongsTo('\\app\\admin\\model\\Store', 'store_id', 'id')->setEagerlyType(1);;
    }

    public function room()
    {
        return $this->belongsTo('\\app\\admin\\model\\Room', 'room_id', 'id')->setEagerlyType(1);;
    }

    public function user()
    {
        return $this->belongsTo('\\app\\admin\\model\\User', 'user_id', 'id')->setEagerlyType(0);
    }

    public function userExtend()
    {
        return $this->belongsTo('\\app\\admin\\model\\user\\Extend', 'user_id', 'user_id')->setEagerlyType(0);
    }

    public function paytransaction()
    {
        return $this->belongsTo('\\app\\admin\\model\\Transaction', 'transaction_id', 'id')->setEagerlyType(0)->joinType('left');
    }

    public function paybalance()
    {
        return $this->belongsTo('\\app\\admin\\model\\user\\Balance', 'balance_id', 'id')->setEagerlyType(0)->joinType('left');
    }

}
